package com.hz.ruoyifarmbase.basedata.controller;

import com.hz.ruoyifarmbase.basedata.domain.AgrGermBreed;
import com.hz.ruoyifarmbase.basedata.service.IAgrGermBreedService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 种质品种Controller
 *
 * @author ruoyi
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/breed")
public class AgrGermBreedController extends BaseController
{
    @Autowired
    private IAgrGermBreedService agrGermBreedService;

    /**
     * 查询种质品种列表
     */
    @RequiresPermissions("basedata:breed:list")
    @GetMapping("/list")
    public TableDataInfo list(AgrGermBreed agrGermBreed)
    {
        startPage();
        List<AgrGermBreed> list = agrGermBreedService.selectAgrGermBreedList(agrGermBreed);
        return getDataTable(list);
    }

    /**
     * 导出种质品种列表
     */
        @RequiresPermissions("basedata:breed:export")
    @Log(title = "种质品种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AgrGermBreed agrGermBreed)
    {
        List<AgrGermBreed> list = agrGermBreedService.selectAgrGermBreedList(agrGermBreed);
        ExcelUtil<AgrGermBreed> util = new ExcelUtil<AgrGermBreed>(AgrGermBreed.class);
        util.exportExcel(response, list, "种质品种数据");
    }

    /**
     * 获取种质品种详细信息
     */
    @RequiresPermissions("basedata:breed:query")
    @GetMapping(value = "/{breedId}")
    public AjaxResult getInfo(@PathVariable("breedId") Long breedId)
    {
        return success(agrGermBreedService.selectAgrGermBreedByBreedId(breedId));
    }

    /**
     * 新增种质品种
     */
    @RequiresPermissions("basedata:breed:add")
    @Log(title = "种质品种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgrGermBreed agrGermBreed)
    {
        return toAjax(agrGermBreedService.insertAgrGermBreed(agrGermBreed));
    }

    /**
     * 修改种质品种
     */
    @RequiresPermissions("basedata:breed:edit")
    @Log(title = "种质品种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgrGermBreed agrGermBreed)
    {
        return toAjax(agrGermBreedService.updateAgrGermBreed(agrGermBreed));
    }

    /**
     * 删除种质品种
     */
    @RequiresPermissions("basedata:breed:remove")
    @Log(title = "种质品种", businessType = BusinessType.DELETE)
	@DeleteMapping("/{breedIds}")
    public AjaxResult remove(@PathVariable Long[] breedIds)
    {
        return toAjax(agrGermBreedService.deleteAgrGermBreedByBreedIds(breedIds));
    }
}
